package com.csdj.service;

import com.csdj.dao.AccountMapper;
import com.csdj.utils.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AccountService {

    @Autowired(required = false)
    private AccountMapper accountMapper;

    /**
     *
     * @param inId 接收
     * @param outId 转出
     * @param money 交易金额
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public ResultInfo transTo(Integer inId,Integer outId,Double money){
       int result1= accountMapper.updateOutMoney(outId,money); //转出 金额
        int i=1/0;
        int result2= accountMapper.updateInMoney(inId,money); //接收 金额
        ResultInfo resultInfo = new ResultInfo();
        if(result1>0&&result2>0){
           resultInfo.setCode(200);
           resultInfo.setMsg("转账成功!");
       }else {
            resultInfo.setCode(500);
            resultInfo.setMsg("转账失败!");
        }
        return resultInfo;
    }

}
